package net.prasenjit.test.bpmn.impl;

import net.prasenjit.test.bpmn.BpmService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: PPurohit
 * Date: 8/15/14
 * Time: 1:36 PM
 * To change this template use File | Settings | File Templates.
 */
@Service
public class BpmServiceImpl implements BpmService {

    private static final String COM_SAMPLE_BPM_HELLO = "com.sample.bpmn.hello";
    private static final String PROCESS_2 = "Process_2";
    private static final String PROCESS_1 = "Process_1";
    private static final String PROCESS_3 = "Process_3";
    @Autowired
    private RuntimeService runtimeService;
    @Autowired
    private TaskService taskService;

    @Override
    public String startSampleProcess(Map<String, Object> argument) {
        ProcessInstance instance = runtimeService.startProcessInstanceByKey(COM_SAMPLE_BPM_HELLO, argument);
        return instance.getId();
    }

    @Override
    public void startProcess2() {
        runtimeService.startProcessInstanceByKey(PROCESS_2);
    }

    @Override
    public void startProcess3() {
        runtimeService.startProcessInstanceByKey(PROCESS_3);
    }

    @Override
    public void completeUserService(String taskId, String userId, Map<String, Object> arguments) {
        taskService.claim(taskId, userId);
        taskService.complete(taskId, arguments);
    }

    @Override
    public List<Task> getAllTask(String userId) {
        return taskService.createTaskQuery().taskCandidateUser(userId).list();
    }
}
